<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>账号管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" maxlength="15" show-word-limit v-model="formInline.q" placeholder="输入关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table class="table" size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60"></el-table-column>
      <el-table-column sortable prop="user_id" label="账号" width="120"></el-table-column>
      <el-table-column align="center" sortable prop="nickname" label="昵称" width="150"></el-table-column>
      <el-table-column align="center" sortable prop="phone" label="手机号" width="150"></el-table-column>
      <el-table-column align="center" sortable prop="auth" label="auth码" width="100"></el-table-column>
      <el-table-column align="center" sortable prop="avatar" label="头像" width="150"></el-table-column>
      <el-table-column align="center" sortable prop="useful" label="状态" width="100">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.useful"
            :active-value="useful.active"
            :inactive-value="useful.inactive"
            @change="handle(scope.row.useful, scope.$index)"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="操作" min-width="150">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleSee(scope.$index, scope.row)">查看</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      background
      layout="prev, pager, next, total"
      :current-page="pageparm.currentPage"
      :page-size="pageparm.pageSize"
      :total="pageparm.total"
      @current-change="changePage"
      @prev-click="changePage"
      @next-click="changePage">
    </el-pagination>

    <!-- 查看 -->
    <el-dialog title="查看信息" :visible.sync="seeFormVisible" width="70%" @click="closeDialog">
      <el-form label-width="120px" :model="seeForm" ref="seeForm">
        <el-form-item label="姓名" prop="player_name">
          <el-input :disabled="true" size="small" maxlength="15" v-model="seeForm.player_name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input :disabled="true" size="small" v-model="seeForm.phone" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="报名等级" prop="obj_grade">
          <el-input :disabled="true" size="small" v-model="seeForm.obj_grade" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="身份证号" prop="id_num">
          <el-input :disabled="true" size="small"  show-word-limit maxlength="18" v-model="seeForm.id_num" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="证件照" prop="id_photo">
          <img v-if="seeForm.id_photo" :src="$store.state.imgUrlPix + seeForm.id_photo" class="avatar">
          <el-input :disabled="true" size="small" v-model="seeForm.id_photo" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group :disabled="true" v-model="seeForm.sex">
            <el-radio label="boy">男</el-radio>
            <el-radio label="girl">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="生日" prop="birthday">
          <el-date-picker :disabled="true" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" v-model="seeForm.birthday"></el-date-picker>
         </el-form-item>
         <el-form-item label="监护人姓名" prop="parent_name">
          <el-input :disabled="true" size="small" maxlength="15" v-model="seeForm.parent_name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="组织" prop="organization">
          <el-input :disabled="true" size="small" v-model="seeForm.organization" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="学校" prop="school">
          <el-input :disabled="true" size="small" v-model="seeForm.school" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="学校就读年级" prop="school_grade">
          <el-input :disabled="true" size="small" v-model="seeForm.school_grade" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { userList } from '../../api/userMG'
export default {
  data() {
    return {
      listData: [],
      formInline: {
        q: '', // 搜索关键字
        page_index: 1,
        page_size: 15,
        token: localStorage.getItem('logintoken')
      },
      useful: {
        active: 1,
        inactive: 0
      },
      seeFormVisible: false,
      seeForm: {
        player_name: '',
        id_num: '',
        birthday: '',
        school_grade: 0,
        sex: '',
        organization: '',
        parent_name: '',
        school: '',
        id_photo: '',

        phone: '',
        obj_grade: '',

        has_pre_pay: 0,
        has_final_pay: 0,
        pay_info: {},

        grade: 0,
        has_passed: 0,
        score: 0,
        result: '',

        // question_list: [],
        // answer_list: [],
        video_url: '',
      },
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 15,
        total: 0
      },
    }
  },
  created() {
    this.getdata(this.formInline)
  },
  methods: {
    changePage(cur){
      this.formInline.page_index = cur;
      this.pageparm.currentPage = cur;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    },

    getdata(parameter) {
      this.loading = true
      let target = {}
      Object.assign(target ,parameter);
      if (!target.q)  delete target.q
      let rep = userList(target)
      rep.then(res => {
          this.loading = false
          if (res.code === 0) {
            this.listData = res.data.list
            this.pageparm.currentPage = this.formInline.page_index
            this.pageparm.pageSize = this.formInline.page_size
            this.pageparm.total = res.total
          } else {
            this.$message({
              type: 'info',
              message: res.msg
            })
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('加载失败，请稍后再试！')
        })
    },
    handleSee: function(index, row) {
      let rep = activityApplicationDetail({main_id: row.main_id})
      rep.then(res => {
        this.loading = false
        if (res.code === 0) {
          this.seeFormVisible = true
          this.seeForm.main_id = row.main_id
          this.seeForm.player_name = row.player_name
          this.seeForm.id_num = row.id_num
          this.seeForm.birthday = row.birthday
          this.seeForm.school_grade = row.school_grade
          this.seeForm.organization = row.organization
          this.seeForm.id_photo = row.id_photo
          this.seeForm.sex = row.sex
          this.seeForm.parent_name = row.parent_name
          this.seeForm.school = row.school

          this.seeForm.phone = row.phone
          this.seeForm.obj_grade = row.obj_grade

          this.seeForm.has_pre_pay = row.has_pre_pay
          this.seeForm.has_final_pay = row.has_final_pay
          this.seeForm.pay_info = row.pay_info

          this.seeForm.grade = row.grade
          this.seeForm.has_passed = row.has_passed
          this.seeForm.score = row.score
          this.seeForm.result = row.result

          this.seeForm.video_url = row.video_url

          this.seeFormVisible = true
        } else {
          this.$message({
            type: 'info',
            message: res.msg
          })
        }
      })
      .catch(err => {
        this.loading = false
        this.$message.error('加载失败，请稍后再试！')
      })
    },
    closeDialog() {
      this.seeFormVisible = false
    }
  }
}
</script>
<style scoped>
.el-breadcrumb {
  margin-bottom: 20px;
}
.el-table--border, .el-table--group {
  margin: 20px 0;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 180px;
  height: 200px;
  line-height: 200px;
  text-align: center;
}
.avatar {
  width: 180px;
  height: 200px;
  display: block;
}
</style>